package org.soderiakelvy.controller.reparto;

import java.io.Serializable;
import java.util.Map;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import org.soderiakelvy.controller.util.Constante;
import org.soderiakelvy.controller.util.Util;
import org.soderiakelvy.model.domain.PersonalVO;
import org.soderiakelvy.model.domain.RolVO;
import org.soderiakelvy.model.service.RepartoServicio;
import org.soderiakelvy.model.service.imp.RepartoServicioImp;

@ManagedBean
@ViewScoped
public class PersonalEdit implements Serializable{
	private static final long serialVersionUID = -8955405538691598747L;
	
	private PersonalVO personal;
	private RepartoServicio service;
	
	//--- Constructor ---
	public PersonalEdit(){
		service = new RepartoServicioImp();
		FacesContext fc = FacesContext.getCurrentInstance();
		Map<String,Object> sessionParams = fc.getExternalContext().getSessionMap();
		personal = (PersonalVO) sessionParams.get("personalEdit");
	}
	
	public String modifcarPersonal(PersonalVO personal){
		personal.setPassword(Util.getMD5(personal.getPassword()));

		service.updatePersonal(personal);
		FacesContext context = FacesContext.getCurrentInstance();
		context.getExternalContext().getSessionMap().remove("personalEdit");
		return Constante.URL_PERSONAL_LIST;
	}
	
	public String cancelar(){
		return Constante.URL_PERSONAL_LIST;
	}
	// --GET AND SET
	public PersonalVO getPersonal() {
		return personal;
	}

	public void setPersonal(PersonalVO personal) {
		this.personal = personal;
	}
	
}
